#pragma once

#include <iostream>
#include <unistd.h>
#include <string>
#include <functional>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include "TcpConnect.hpp"

class TcpClient
{

public:
    TcpClient(uint16_t port, std::string ip)
        : _tc(port, ip)
    {
    }

    void TestConnect()
    {
        while (1)
        {
            switch (_tc.GetStatus())
            {
            case TcpConnect::Status::New:
                _tc.Connect();
                break;
            case TcpConnect::Status::Connected:
                Excute();
                break;
            case TcpConnect::Status::Reconnect:
                _tc.Reconnect();
                break;
            case TcpConnect::Status::Disconnect:
                std::cout << "连接失败，退出" << std::endl;
                _tc.Disconnect();
                return;
            }
        }
    }

    void Excute()
    {
        while (true)
        {
            std::cout << "连接成功,执行任务ing……" << std::endl;
            sleep(1);
        }
    }

    ~TcpClient()
    {
    }

private:
    TcpConnect _tc;
};